<template>
  <view v-if="appointmentInfo&&appointmentInfo.type===1">
    <Maintain @on-handle="handleMaintain"></Maintain>
  </view>
  <view v-if="appointmentInfo&&appointmentInfo.type===2">
    <Catheter @on-handle="handleCatheter"></Catheter>
  </view>
  <view v-if="appointmentInfo&&appointmentInfo.type===3">
    <Extubation @on-handle="handleExtubation"></Extubation>
  </view>


</template>

<script setup lang="ts">
import {onLoad} from "@dcloudio/uni-app";
import {ref} from "vue";
import Catheter from "@/pages/nurse/appointment/handle/components/Catheter.vue";
import Maintain from "@/pages/nurse/appointment/handle/components/Maintain.vue";
import Extubation from "@/pages/nurse/appointment/handle/components/Extubation.vue";
import api from "@/api";


onLoad((option) => {
  appointmentInfo.value = JSON.parse(decodeURIComponent(option.appointmentInfo))
  console.log(appointmentInfo.value)
})
const appointmentInfo = ref()


const handleMaintain = (e: any) => {
  api.treat.maintainCreate({
    appointmentId:appointmentInfo.value.id,
    patientUsername:appointmentInfo.value.patientUsername,
    patientName:appointmentInfo.value.patientName,
    nurseUsername:appointmentInfo.value.nurseUsername,
    nurseName:appointmentInfo.value.nurseName,

    pipelineUnobstructed: e.pipelineUnobstructed,
    changeDressing: e.changeDressing,
    replaceConnector: e.replaceConnector,
    resistance: e.resistance,
    companion: e.companion,
    bloodReturn: e.bloodReturn,
    catheterExposedLength: e.catheterExposedLength,
    images:JSON.stringify(e.images)
  }).then(res=>{
    if(res&&res.data.code===0){
      uni.showToast({
        title:res.data.msg,
        icon:'success',
        success:()=>{
          uni.navigateBack()
        }
      })
    }
  })
}
const handleCatheter = (e: any) => {
  api.treat.catheterCreate({
    appointmentId:appointmentInfo.value.id,
    patientUsername:appointmentInfo.value.patientUsername,
    patientName:appointmentInfo.value.patientName,
    nurseUsername:appointmentInfo.value.nurseUsername,
    nurseName:appointmentInfo.value.nurseName,

    disease: e.disease,
    firstCatheter: e.firstCatheter,
    catheterOpportunity: e.catheterOpportunity,
    catheterSpecification: e.catheterSpecification,
    catheterModel: e.catheterModel,
    catheterLength: e.catheterLength,
    punctureMethod: e.punctureMethod,
    catheterSite:e.catheterSite,
    catheterArm:e.catheterArm,
    catheterVein:e.catheterVein,
    catheterTipPosition:e.catheterTipPosition,
    catheterInsertionLength:e.catheterInsertionLength,
    catheterExposedLength:e.catheterExposedLength,
    images:JSON.stringify(e.images)
  }).then(res=>{
    if(res&&res.data.code===0){
      uni.showToast({
        title:res.data.msg,
        icon:'success',
        success:()=>{
          uni.navigateBack()
        }
      })
    }
  })

}
const handleExtubation = (e: any) => {
  api.treat.extubationCreate({
    appointmentId:appointmentInfo.value.id,
    patientUsername:appointmentInfo.value.patientUsername,
    patientName:appointmentInfo.value.patientName,
    nurseUsername:appointmentInfo.value.nurseUsername,
    nurseName:appointmentInfo.value.nurseName,

    indwellingTime: e.indwellingTime,
    endIntact: e.endIntact,
    processSmooth: e.processSmooth,
    images:JSON.stringify(e.images)
  }).then(res=>{
    if(res&&res.data.code===0){
      uni.showToast({
        title:res.data.msg,
        icon:'success',
        success:()=>{
          uni.navigateBack()
        }
      })
    }
  })

}
</script>

<style scoped>

</style>
